<?php

use backend\models\TbaDeliveryinfo;


if(\yii::$app->request->isPost){
   
	$start=intval(\yii::$app->request->post('start'));    //起始数据条数
	$length=intval(\yii::$app->request->post('length'));  //需要显示的数据条数
	$draw=intval(\yii::$app->request->post('draw'));      
	
	$column=intval(\yii::$app->request->post('order')[0]['column']);   //排序的列
	$dir = \yii::$app->request->post('order')[0]['dir'];     //排序方式
	
	$columArry=[
	
		"1"=>"ID",
		"2"=>"DeliveryName",
		"3"=>"DeliveryID",
		"4"=>"LinkName",
		"5"=>"Address",
		"6"=>"LinkTel",
		"7"=>"QQ",
		"8"=>"Email",
		
	];
	
	
	//构建排序条件
	if($column == 0){
		$cloumName=$columArry[1];
	}else{	
		$cloumName=$columArry[$column];
	}
	
		
	//根据搜索值时构建查询条件
	if(\yii::$app->request->post('search')['value']!=""){
		
		$value=\yii::$app->request->post('search')['value'];
		if(is_string($value))
			$where=" DeliveryName like '%".$value."%'  or DeliveryID like '%".$value."%'  or LinkName like '%".$value."%' or Address like '%".$value."%' or LinkTel like '%".$value."%' or QQ like '%".$value."%' or Email like '%".$value."%' ";
		if(is_numeric($value))
		$where = "ID like '%".$value."%' or QQ like '%".$value."%' or LinkTel like '%".$value."%' ";
		
	}else{						
			$where="";				
	}
		
	
	//根据条件查询数据
    $order = TbaDeliveryinfo::find()->where($where)->orderBy($cloumName." ".$dir)->limit($length)->offset($start)->all();   //实例化配送商AR模型
    $total =count($order);  //查询数据总数
    $arr=[];
    foreach ($order as $v){
		
    	$temp=[];
    	$temp['check']=" <label class=\"pos-rel\">															
 							<input type='checkbox' name='check[]'  value=".$v['ID']."  class='ace'>
 							<span class='lbl'></span>
 					   </label>";
    	$temp['ID']=$v['ID'];
    	$temp['DeliveryName']=$v['DeliveryName'];  	
    	$temp['DeliveryID']=$v['DeliveryID'];
    	$temp['LinkName']=$v['LinkName'];
    	$temp['Address']=$v['Address'];
    	$temp['LinkTel']=$v['LinkTel'];
    	$temp['QQ']=$v['QQ'];
    	$temp['Email']=$v['Email'];
    	$temp['options']="<center><div class='hidden-sm hidden-xs action-buttons'>
								<!--<a class='blue' href='#' onclick='return see(".$v['ID'].")'>
									<i class='ace-icon fa fa-search-plus bigger-130'></i>   							
								</a>-->

								<a class='green' href='#' onclick='return alter(".$v['ID'].")' >
									<i class='ace-icon fa fa-pencil bigger-130'></i>
								</a>

								<a class='red' href='#' onclick='return delet(".$v['ID'].")' >
									<i class='ace-icon fa fa-trash-o bigger-130'></i>
								</a>
							</div></center>";
    	 	
  	 	$arr[]=$temp;
  	 	   
    }
	    
    //构造返回数据
    $tmp=[
 	   "draw"=>$draw,
 	   "recordsTotal"=>$total,     //数据综述
 	   "recordsFiltered"=>$total,  //数据总数
 	   "data"=>$arr                //数据
   
    ];
   
    echo  json_encode($tmp);  //将数据转变为json字符串

}

?>